package com.ala4.oxcafe.controller;

import com.ala4.oxcafe.boot.ExcelExport;
import com.ala4.oxcafe.boot.page.PageDomain;
import com.ala4.oxcafe.boot.page.PageResult;
import com.ala4.oxcafe.common.utils.JSONUtil;
import com.ala4.oxcafe.common.utils.SmsClientUtil;
import com.ala4.oxcafe.domain.R;
import com.ala4.oxcafe.entity.TestEntity;
import com.ala4.oxcafe.entity.TestUserInfo;
import com.ala4.oxcafe.repository.TestUserInfoRepository;
import com.aliyun.sms.SMSPutDTO;
import com.aliyun.sms.SMSTemplateEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;
import java.util.List;

/**
 * @author PING
 * @version 1.0.0
 * @date 2025/7/31 15:30
 */
@RestController
@RequestMapping("/test")
@Tag(name = "测试接口", description = "测试接口")
public class TestController {

    @Resource
    private TestUserInfoRepository testUserInfoRepository;

    @GetMapping("/str")
    public String str() {
        TestEntity testEntity = new TestEntity(982716387163L, "李四", 88, new BigDecimal("88556.33222"), LocalDateTime.now(), LocalDate.now(), LocalTime.now(), new Date());
        return JSONUtil.toJsonStr(testEntity);
    }

    @GetMapping("/test-user")
    public TestUserInfo testUserInfo() {
        return testUserInfoRepository.getById(1904084261895084403L);
    }

    @Operation(summary = "分页查询测试用户菜单列表")
    @GetMapping("/list")
    @ExcelExport(value = TestUserInfo.class, excelName = "测试用户菜单")
    public PageResult<TestUserInfo> list(PageDomain pageDomain, TestUserInfo testUserInfo) {
        return PageResult.iPage(testUserInfoRepository.selectTestUserInfoPage(pageDomain, testUserInfo));
    }

    @Operation(summary = "分页查询测试用户菜单列表")
    @GetMapping("/export-list")
    @ExcelExport(value = TestUserInfo.class, excelName = "测试用户菜单")
    public List<TestUserInfo> list(TestUserInfo testUserInfo) {
        LambdaQueryWrapper<TestUserInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.gt(TestUserInfo::getId, 1904084261895185373L);
        return testUserInfoRepository.list(queryWrapper);
    }

    @GetMapping("/expt")
    public R<String> expt() {
        try {
            int a = 1 / 0;
        } catch (Exception e) {
            throw new RuntimeException("调用方法出现异常", e);
        }
        return R.ok("123");
    }

    @PostMapping("/expt")
    public R<TestUserInfo> expt2(@RequestBody @Validated TestUserInfo testUserInfo) {
        return R.ok(testUserInfo);
    }


    @PostMapping("/test-sms")
    @Operation(summary = "测试发送短信")
    public R<?> testSms() {
        SMSPutDTO smsPutDTO = new SMSPutDTO();
//        smsPutDTO.setPhoneNumbers("15989735076"); // 移动
        smsPutDTO.setPhoneNumbers("13352798814"); // 电信
//        smsPutDTO.setPhoneNumbers("13170872631"); // 联通
        smsPutDTO.setSmsTemplateEnum(SMSTemplateEnum.CAPTCHA);
        smsPutDTO.setTemplateParam("{\"code\":\"7654\"}");
        SmsClientUtil.sendSms(smsPutDTO);
        return R.ok();
    }
}
